
TOOLCHAIN = i586-elf-

export CC = $(TOOLCHAIN)gcc
export LD = $(TOOLCHAIN)ld
export AS = $(TOOLCHAIN)as
export OBJCOPY = $(TOOLCHAIN)objcopy
export OBJDUMP = $(TOOLCHAIN)objdump
export MAKE = make

SUBDIRS = sys

all: alldirs kernel bootimage

alldirs:
	@for i in $(SUBDIRS); do \
	echo "making all in $$i"; \
	(cd $$i; $(MAKE) all); done

kernel:
	$(LD) -e startup_bsp -Ttext 0xc0050000 -o obj/kernel sys/dev/*.o sys/arch/x86/*.o sys/kern/*.o sys/klibc/*.o sys/bus/*.o -b binary sys/boot/x86/trampoline

bootimage:
	dd if=sys/boot/x86/boot0 of=boot.img conv=notrunc
	dd if=obj/kernel of=boot.img seek=1 conv=notrunc

clean:
	@for i in $(SUBDIRS); do \
	echo "cleaning $$i"; \
	(cd $$i; $(MAKE) clean); done
	rm boot.img obj/kernel

